---
--类名: WorldBattleController.lua
--创建日期: 2018-9-6
--创建人: 宋建邦
--功能描述:领地争夺战地图控制器
--修改内容:
--修改日期:
--修改人:
--修改备注:

local WorldBattleView = import("..views.WorldBattleView")
local BattleMapModel = import("..models.BattleMapModel")

local fileName = string.getModeName(...)
local WorldBattleController = class(fileName, app.mvc.ControllerBase)

function WorldBattleController:ctor(params)
    self.super.ctor(self, params)
end

function WorldBattleController:init()
    self.worldMapModel = app:getInst("WorldMapModel")
end

function WorldBattleController:openView()
    local bc = app:getInst("BiddingController")
    if bc.battleMapModel == nil then
        bc:reqTownList()
        self.EMhandler = nil
        self.EMhandler = EM:on(bc.townlistChange, function()
            self:doOpenView()
            EM:remove(self.EMhandler)
            EM:notify(bc.townlistChange)
        end)
    else
        self:doOpenView()
        bc:reqTownList()
    end
end

function WorldBattleController:doOpenView()
    local bc = app:getInst("BiddingController")
    if bc.battleMapModel.townInfos[1].data.phase == "CLOSE" then
        display.pushToast(L"bidding_tips_not_open")
        return
    end
    if cc.isDead(self._view) then
		self._view = WorldBattleView.new(app.mvc.VIEWTYPE_BLUR)
		self._view:onCloseView(handler(self, self.closeView))
		self._view:onClearView(handler(self, self.clearView))
	end
    self:addChild(self._view)
end

function WorldBattleController:clearView()
	if self._view then 
		self._view = nil
	end
end

return WorldBattleController